<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>


    </style>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
    <script>
        let ul = document.getElementsByTagName('ul')[0]
        
        ul.onclick = function (e) {
            e.target.style.background='green'
        }
        // 新加多个li
        let str = '' //html字符串拼接，重新赋值原来html结构事件丢失，样式不会丢失。
        for (let i = 0; i < 7; i++) {
            // let newli = document.createElement('li')
            str += `<li>newli</li>`
        }
        ul.innerHTML += str


    </script>
</body>

</html>